package com.tj.jinzao.adapter;

import android.app.Activity;
import android.database.Cursor;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.tj.jinzao.R;
import com.tj.jinzao.base.RecyclerViewCursorAdapter;
import com.tj.jinzao.provider.ProviderContract;


/**
 * cityAdapter
 * Created by wjy on 2018/5/22.
 */
public class CityItemAdapter extends RecyclerViewCursorAdapter<CityItemAdapter.ViewHolder> {

    private String mSelectedId;

    public CityItemAdapter(Activity context, Cursor cursor) {
        super(context, cursor);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
        }
    }
    public void setSelectedId(String selectedId) {
        this.mSelectedId = selectedId;
        notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_occupation, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, Cursor cursor) {
        String name = cursor.getString(cursor.getColumnIndex(ProviderContract.City.CITY_NAME));
        String code = cursor.getString(cursor.getColumnIndex(ProviderContract.City.CITY_CODE));
        holder.name.setText(name);
        holder.name.setActivated(TextUtils.equals(code, mSelectedId));
    }
}
